﻿#region

using System;
using System.IO;
using System.Text;
using System.Web.Mvc;
using CuongHanh.Context;
using CuongHanh.Models;

#endregion

namespace CuongHanh.Controllers.FO
{
    public class StaticPageController : BaseController
    {
        public ActionResult Index(int id)
        {
            string language = GetLanguage();
            string content = string.Empty;
            StaticPage item = CacheContext<StaticPage>.Singleton.GetObject(id);
            if (item==null)
                return View(new Tuple<string, string>("",
                        content));
            string title = item.NameVi;
            if(language == AppUtil.LANGUAGE_EN)
                title = item.NameEn;
            string path = Server.MapPath(string.Format("~/{0}{1}.html",
                item.PhysicalFile,language==AppUtil.LANGUAGE_EN?"-en":""));
            if(!System.IO.File.Exists(path))
                return View(new Tuple<string, string>(title,
                        content));
            using (StreamReader reader = new StreamReader(path,
                    Encoding.GetEncoding("ISO-8859-1")))
            {
                content = reader.ReadToEnd();
            }
            return View(new Tuple<string, string>(title,
                    content));
        }
    }
}
